﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EZCRS.HCMS.SqlClient;

namespace EZCRS.HCMS.Bll.userinfo
{
    public class Bllcompanyinfo:MainBase
    {
        private string SqlStr = "", ErrMsg = "";

        #region 添加或修改公司
        /// <summary>
        /// 添加或修改
        /// </summary>
        /// <param name="CompanyId">企业编号 0 为新增</param>
        /// <param name="GId"></param>
        /// <param name="PId"></param>
        /// <param name="CompanyName"></param>
        /// <param name="CompanyNameE"></param>
        /// <param name="CompanyType"></param>
        /// <param name="AddressCountry"></param>
        /// <param name="AddrProvince"></param>
        /// <param name="AddrCity"></param>
        /// <param name="Address"></param>
        /// <param name="Post"></param>
        /// <param name="CompanyTel"></param>
        /// <param name="CompanyFax"></param>
        /// <param name="CompanyEmail"></param>
        /// <param name="FirstName"></param>
        /// <param name="LastName"></param>
        /// <param name="Gender"></param>
        /// <param name="Tel"></param>
        /// <param name="Email"></param>
        /// <param name="Orate"></param>
        /// <param name="Iata"></param>
        /// <param name="Status"></param>
        /// <returns></returns>
        public bool Company_Add(int CompanyId, int GId, int PId, string CompanyName, string CompanyNameE, string CompanyType, string AddressCountry, string AddrProvince, string AddrCity, string Address, string Post, string CompanyTel, string CompanyFax, string CompanyEmail, string FirstName, string LastName, string Gender, string Tel, string Email, string Orate, string Iata, string Status)
        {
            return new sql_AdmCompany().Company_Add(CompanyId, GId, PId, CompanyName, CompanyNameE, CompanyType, AddressCountry, AddrProvince, AddrCity, Address, Post, CompanyTel, CompanyFax, CompanyEmail, FirstName, LastName, Gender, Tel, Email, Orate, Iata, Status);
        }
        #endregion

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="StrWhere"></param>
        /// <returns></returns>
        public DataSet Company_List(int PageSize, int PageIndex, string StrWhere)
        {
            return new sql_AdmCompany().Company_List(PageSize, PageIndex, StrWhere);
        }

        /// <summary>
        /// 删除企业
        /// </summary>
        /// <param name="CompanyId">企业编号</param>
        /// <returns></returns>
        public bool Company_Del(string CompanyId)
        {
            return new sql_AdmCompany().Company_Del(CompanyId);
        }

        /// <summary>
        /// 企业状态
        /// </summary>
        /// <returns></returns>
        public DataTable Company_Status()
        {
            string[] LogData = Common.DoubleStatus;

            DataTable dt = new DataTable();
            DataColumn dc1 = dt.Columns.Add("sid", Type.GetType("System.String"));
            DataColumn dc2 = dt.Columns.Add("sname", Type.GetType("System.String"));


            for (int i = 0; i < LogData.Length; i++)
            {
                DataRow dr = dt.NewRow();
                dr["sid"] = LogData[i].Split(',')[0];
                dr["sname"] = LogData[i].Split(',')[LanguageNumber+1];

                dt.Rows.Add(dr);
            }
            return dt;
        }

        /// <summary>
        /// 获得行业类型数据
        /// </summary>
        /// <returns></returns>
        public DataTable Company_BussType()
        {
            return new sql_AdmCompany().Company_BussType();
        }

        /// <summary>
        /// 根据corpid获取DataRow
        /// </summary>
        /// <param name="corpid"></param>
        /// <returns></returns>
        public DataRow GetCompanyListOne(int corpid)
        {
            return new sql_AdmCompany().GetCompanyListOne(corpid);
        }

        /// <summary>
        /// 查找[hfg_company_user]表中是否存在此公司
        /// </summary>
        /// <param name="corpid">公司ID</param>
        /// <returns>存在：true 不存在：false</returns>
        public bool CheckCompanyUser(int corpid)
        {
            return new sql_AdmCompany().CheckCompanyUser(corpid);
        }




        //====================================

        /// <summary>
        /// 添加或修改公司客信息
        /// </summary>
        /// <param name="usrid">用户ID</param>
        /// <param name="corpid">所属公司ID</param>
        /// <param name="usrnumb">用户卡号</param>
        /// <param name="usrpass">用户密码</param>
        /// <param name="usrstatus">用户是否锁定</param>
        /// <param name="inuser">创建人</param>
        /// <returns></returns>
        public bool CompanyUser_Add(int usrid, int corpid, string usrnumb, string usrpass, string usrstatus, string inuser, int gid, int pid, string createtime)
        {
            return new sql_AdminCompanyUser().CompanyUser_Add(usrid, corpid, usrnumb, usrpass, usrstatus, inuser, gid, pid, createtime);
        }

        /// <summary>
        /// 生成随即密码 5 位数字
        /// </summary>
        /// <returns></returns>
        public static string CreatePassword()
        {
            Random r = new Random();
            int rl = r.Next(10000, 99999);
            return rl.ToString();
        }

        /// <summary>
        /// 密码初始化
        /// </summary>
        /// <param name="usrid">用户ID</param>
        /// <returns></returns>
        public string ResetUserPassword(int usrid)
        {
            return new sql_AdminCompanyUser().ResetUserPassword(usrid);
        }

        /// <summary>
        /// 判断是否存在相同卡号的用户存在
        /// </summary>
        /// <param name="usrnumb">用户卡号</param>
        /// <returns></returns>
        public bool CheckSameUser(string usrnumb)
        {
            return new sql_AdminCompanyUser().CheckSameUser(usrnumb);
        }

        /// <summary>
        /// 删除公司客信息
        /// </summary>
        /// <param name="usrid">用户ID</param>
        /// <returns></returns>
        public bool CompnayUser_Del(int usrid)
        {
            return new sql_AdminCompanyUser().CompnayUser_Del(usrid);
        }

        /// <summary>
        /// 获取所属公司数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetUserOfCompany(int Gid, int Pid)
        {
            return new sql_AdminCompanyUser().GetUserOfCompany(Gid, Pid);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="StrWhere"></param>
        /// <returns></returns>
        public DataSet GetCompanyUserList(int PageSize, int PageIndex, string StrWhere)
        {
            return new sql_AdminCompanyUser().GetCompanyUserList(PageSize, PageIndex, StrWhere);
        }

        /// <summary>
        /// 根据UserId获取DataRow
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public DataRow GetCompanyUserOne(int UserId)
        {
            return new sql_AdminCompanyUser().GetCompanyUserOne(UserId);
        }



    }
}
